package com.example.serenity.service;

import com.example.serenity.controller.model.Query;
import com.example.serenity.dao.MessageMapper;
import com.example.serenity.entity.Message;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class MessageServiceImp implements MessageService{
    @Resource
    private MessageMapper messageMapper;
    @Override
    @Transactional
    public PageInfo<Message> getList(Query query) {
        if(query.getPageNum()==null)    query.setPageNum(1);
        if(query.getPageSize()==null) query.setPageSize(10);
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        return new PageInfo<Message>(messageMapper.getList(query));
    }
}
